package com.fr.report.highlight;

import com.fr.base.Style;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.CellElement;
import com.fr.report.Report;
import com.fr.report.script.Calculator;
import java.util.Iterator;

public class PaddingHighlightAction extends AbstractHighlightAction
{
  private byte paddingLeft = 2;
  private byte paddingRight = 2;
  private int scope = 0;

  public PaddingHighlightAction()
  {
  }

  public PaddingHighlightAction(byte paramByte1, byte paramByte2, int paramInt)
  {
    this.paddingLeft = paramByte1;
    this.paddingRight = paramByte2;
    this.scope = paramInt;
  }

  public byte getPaddingLeft()
  {
    return this.paddingLeft;
  }

  public void setPaddingLeft(byte paramByte)
  {
    this.paddingLeft = paramByte;
  }

  public byte getPaddingRight()
  {
    return this.paddingRight;
  }

  public void setPaddingRight(byte paramByte)
  {
    this.paddingRight = paramByte;
  }

  public int getScope()
  {
    return this.scope;
  }

  public void setScope(int paramInt)
  {
    this.scope = paramInt;
  }

  public void action(CellElement paramCellElement, Calculator paramCalculator)
  {
    if (paramCellElement == null)
      return;
    Report localReport = paramCalculator.getCurrentReport();
    switch (getScope())
    {
    case 1:
      if (localReport == null)
        return;
      int i = paramCellElement.getRow();
      Iterator localIterator1 = localReport.getRow(i);
      while (true)
      {
        if (!(localIterator1.hasNext()))
          return;
        modifyPadding((CellElement)localIterator1.next(), this.paddingLeft, this.paddingRight);
      }
    case 2:
      if (localReport == null)
        return;
      int j = paramCellElement.getColumn();
      Iterator localIterator2 = localReport.getColumn(j);
      while (true)
      {
        if (!(localIterator2.hasNext()))
          return;
        modifyPadding((CellElement)localIterator2.next(), this.paddingLeft, this.paddingRight);
      }
    }
    modifyPadding(paramCellElement, this.paddingLeft, this.paddingRight);
  }

  private void modifyPadding(CellElement paramCellElement, byte paramByte1, byte paramByte2)
  {
    paramCellElement.setStyle(paramCellElement.getStyle().derivePadding(paramByte1, paramByte2));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1;
      String str2 = paramXMLableReader.getTagName();
      if ("Padding".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("left")) != null)
          setPaddingLeft((byte)Integer.parseInt(str1));
        if ((str1 = paramXMLableReader.getAttr("right")) != null)
          setPaddingRight((byte)Integer.parseInt(str1));
      }
      if ("Scope".equals(str2))
        if ((str1 = paramXMLableReader.getAttr("val")) != null)
          setScope(Integer.parseInt(str1));
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Padding").attr("left", this.paddingLeft).attr("right", this.paddingRight).end();
    if (getScope() != 0)
      paramXMLPrintWriter.startTAG("Scope").attr("val", getScope()).end();
  }
}